﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DrugStorehouseMIS.Comm;
using DrugStorehouseMIS.DAL.Interface;

namespace DrugStorehouseMIS.DAL
{
    public class UserGroupDAL:IUserGroupDAL
    {
        #region IUserGroupDAL 成员

        public IDataReader Select(int UserGroupNum)
        {
            try
            {
                return SqlDbHelper.RunProcedure_Reader(ConnectionString.ConnString, "Proc_UserGroup_Select", new SqlParameter[] { new SqlParameter("@UserGroupNum", UserGroupNum) });
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }        
        }

        public int Insert(string UserGroupName, int UserGroupType, string CreatedBy, string LastUpdatedBy, int FlagDisable)
        {
            try
            {
                SqlParameter[] all = new SqlParameter[]
                {
                    new SqlParameter("@UserGroupName",UserGroupName),
                    new SqlParameter("@UserGroupType",UserGroupType),
                    new SqlParameter("@CreatedBy",CreatedBy),
                    new SqlParameter("@LastUpdatedBy",LastUpdatedBy),
                    new SqlParameter("@FlagDisable",FlagDisable)
                };

                return SqlDbHelper.RunProcedure_Query(ConnectionString.ConnString, "Proc_UserGroup_Insert", all);
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }        
        }

        public int Update(int UserGroupNum, string UserGroupName, int UserGroupType, string LastUpdatedBy, int FlagDisable)
        {
            try
            {
                SqlParameter[] all = new SqlParameter[]
                {
                    new SqlParameter("@UserGroupNum",UserGroupNum),
                    new SqlParameter("@UserGroupName",UserGroupName),
                    new SqlParameter("@UserGroupType",UserGroupType),
                    new SqlParameter("@LastUpdatedBy",LastUpdatedBy),
                    new SqlParameter("@FlagDisable",FlagDisable)
                };

                return SqlDbHelper.RunProcedure_Query(ConnectionString.ConnString, "Proc_UserGroup_Update", all);
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }           
        }

        public int Delete(int UserGroupNum)
        {
            try
            {
                return SqlDbHelper.RunProcedure_Query(ConnectionString.ConnString, "Proc_UserGroup_Query", new SqlParameter[] { new SqlParameter("@UserGroupNum", UserGroupNum) });
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }     
        }

        #endregion
    }
}
